import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xiaomi_shop/app/api/api.dart';
import 'package:xiaomi_shop/app/services/keepAliveWrapper.dart';
import 'package:xiaomi_shop/app/services/screenAdapter.dart';
import 'package:xiaomi_shop/app/widget/refreshListView.dart';

import '../controllers/order_list_controller.dart';

class OrderListView extends GetView<OrderListController> {
  const OrderListView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: const Text('订单列表'),
          centerTitle: true,
          bottom: PreferredSize(
              preferredSize: Size.fromHeight(ScreenAdapter.height(80)),
              child: Obx(
                () => controller.tabLists.isEmpty
                    ? Text("")
                    : TabBar(
                        controller: controller.tabController,
                        labelStyle:
                            TextStyle(fontSize: ScreenAdapter.fontSize(44)),
                        labelColor: Colors.orange.shade900,
                        indicatorColor: Colors.orange.shade900,
                        unselectedLabelStyle:
                            TextStyle(fontSize: ScreenAdapter.fontSize(44)),
                        overlayColor:
                            const MaterialStatePropertyAll(Colors.white),
                        tabs: controller.tabLists.value.map((e) {
                          return Tab(
                            text: e["title"],
                          );
                        }).toList(),
                        onTap: (value) {
                          print(value);
                        },
                      ),
              ))),
      body: Obx(() => controller.tabLists.value.isEmpty
          ? const Center(
              child: Text("暂无数据"),
            )
          : TabBarView(
              controller: controller.tabController,
              children: controller.tabLists.value.map((e) {
                return KeepAliveWrapper(
                    child: RefreshListView(
                  url: Api.orderList,
                  argument: {},
                  onTap: (model) {
                    Get.toNamed("/order-detail", arguments: model);
                  },
                ));
              }).toList())),
    );
  }
}
